<?php

require_once(DIR_LIB."VsGui".DIR_SEP."vssmartywidget.php");

require_once(DIR_LIB."Junona".DIR_SEP."junobjectsfactory.php");

class XCartOperators extends VsSmartyWidget {

	function __construct(&$page, $pager=NULL) {
		// Ne go zabravqj ina4e nqma $smarty Object
		parent::__construct();

		$this->_template = dirname(__FILE__).DIR_SEP."xcart_operators_groups.html";

		$this->_wwwDir = 'templates/XCart/';
		$this->assign('wwwDir', $this->_wwwDir);

		//$page->addJsFile($this->_wwwDir."js/popup_image_selection.js");
		$page->addJsCode($this->jsfuncRadioValue());


		if(isset($_POST['sub_group'])) {
			$this->procForm();
		}
		
		$groups = JunObjectsFactory::makeOperatorGroups();
		$this->assign('listGroups', $groups);

		if($pager)
			$this->assign('pager', $pager->show());
		else
			$this->assign('pager', '');

	}
	//============================================================================

	function show() {

		return $this->fetch($this->_template);
	}
	//============================================================================

	private function procForm() {
		//$model = JunOperator::makeFromForm($_POST);
		//$model->save();

		JunObjectsFactory::addOperatorGroup($_POST['name']);

		header("Location: ".$_SERVER['PHP_SELF']);
	}
	//===========================================================================

	private function jsfuncRadioValue() {
		$js = "function radioValue(radio) {";
		$js .= "	for (var i=0; i < radio.length; i++) {";
		$js .= "		if (radio[i].checked)";
		$js .= "			return radio[i].value;";
		$js .= "	}";
		$js .= "}";

		return $js;
	}
	//===========================================================================

};

?>
